<template>
  <div>
    <Row class="header" type="flex" justify="start">
      <Col span="24">
        <Icon class="icon" type="ios-trending-up"/>
        <span class="title">来沈人员走势</span>
      </Col>
    </Row>
    <br>
    <div id="cityTime" :style="{ width: width + 'px', height: height + 'px'}"></div>
  </div>
</template>

<script>
import echarts from 'echarts'
import { sumAddressTypeDate } from '@/api/yi-qing-fang-kong'
// import mockData from './mockData'

export default {
  name: 'CityTimeEchart',
  data () {
    return {
      chartData: []
    }
  },
  props: {
    width: {
      type: Number,
      default: () => {
        return 500
      }
    },
    height: {
      type: Number,
      default: () => {
        return 300
      }
    }
  },
  mounted () {
    this.chart()
  },
  methods: {
    chart () {
      sumAddressTypeDate().then(ret => {
        if (ret.data.errcode === 0) {
          this.chartData = ret.data.data
          let option = {
            title: {
              text: ''
            },
            legend: {
              left: '20%',
              itemHeight: 10,
              padding: [0, 0, 10, 0]
            },
            textStyle: {
              color: '#bababa'
            },
            tooltip: {
              trigger: 'axis',
              backgroundColor: 'rgba(50,50,50,0.6)'
            // formatter: function (params) {
            //   params = params[0]
            //   const date = new Date(params.value.measure_time)
            //   return date.getFullYear().toString().padStart(4, '0') + '-' +
            //     (date.getMonth() + 1).toString().padStart(2, '0') + '-' +
            //     date.getDate().toString().padStart(2, '0') + '<br>' +
            //     date.getHours().toString().padStart(2, '0') + ':' +
            //     date.getMinutes().toString().padStart(2, '0') + ':' +
            //     date.getSeconds().toString().padStart(2, '0') + '<br>' +
            //     params.value.temperature + '℃'
            // }
            },
            dataset: {
              dimensions: ['date', 'zjwz', 'inwh', 'outwh', 'otherwh', 'datian'],
              source: []
            },
            yAxis: {
              name: '单位：人',
              type: 'value',
              axisLine: {
                lineStyle: {
                  color: '#bababa' // 轴及其文字颜色
                },
                show: false
              }
            },
            xAxis: {
              name: '',
              boundaryGap: true,
              type: 'category',
              axisLine: {
                lineStyle: {
                  color: '#bababa' // 轴及其文字颜色
                },
                show: true
              },
              axisLabel: {
                formatter: function (val, index) {
                  const date = new Date(val)
                  const name = date.getFullYear() + '.' + (date.getMonth() + 1) + '.' + date.getDate()
                  // const name = (date.getMonth() + 1) + '.' + date.getDate()
                  return name
                },
                interval: 'auto',
                rotate: 40
              },
              splitLine: {
                show: false
              }
            },
            series: [
              {
                name: '浙江温州',
                type: 'line',
                smooth: true,
                symbolSize: 8,
                label: {
                // normal: {
                //   show: true,
                //   position: 'inside',
                //   color: ['#fff']
                // }
                },
                itemStyle: {
                // 通常情况下：
                  normal: {
                    color: ['#F49F42']
                  },
                  areaStyle: {},
                  // 鼠标悬停时：
                  emphasis: {
                    shadowBlur: 10,
                    shadowOffsetX: 0,
                    shadowColor: 'rgba(0, 0, 0, 0.5)'
                  }
                }
              },
              {
                name: '湖北武汉',
                type: 'line',
                smooth: true,
                symbolSize: 8,
                label: {
                // normal: {
                //   show: true,
                //   position: 'inside',
                //   color: ['#fff']
                // }
                },
                itemStyle: {
                // 通常情况下：
                  normal: {
                    color: ['#BC3139']
                  },
                  areaStyle: {},
                  // 鼠标悬停时：
                  emphasis: {
                    shadowBlur: 10,
                    shadowOffsetX: 0,
                    shadowColor: 'rgba(0, 0, 0, 0.5)'
                  }
                }
              },
              {
                name: '湖北非武汉',
                type: 'line',
                smooth: true,
                symbolSize: 8,
                label: {
                // normal: {
                //   show: true,
                //   position: 'inside',
                //   color: ['#fff']
                // }
                },
                itemStyle: {
                // 通常情况下：
                  normal: {
                    color: ['#FB7293']
                  },
                  areaStyle: {},
                  // 鼠标悬停时：
                  emphasis: {
                    shadowBlur: 10,
                    shadowOffsetX: 0,
                    shadowColor: 'rgba(0, 0, 0, 0.5)'
                  }
                }
              },
              {
                name: '其它省市',
                type: 'line',
                smooth: true,
                symbolSize: 8,
                label: {
                // normal: {
                //   show: true,
                //   position: 'inside',
                //   color: ['#fff']
                // }
                },
                itemStyle: {
                // 通常情况下：
                  normal: {
                    color: ['#37A2DA']
                  },
                  areaStyle: {},
                  // 鼠标悬停时：
                  emphasis: {
                    shadowBlur: 10,
                    shadowOffsetX: 0,
                    shadowColor: 'rgba(0, 0, 0, 0.5)'
                  }
                }
              }
            /* {
              name: '尚未设置',
              type: 'line',
              smooth: true,
              symbolSize: 8,
              label: {
                // normal: {
                //   show: true,
                //   position: 'inside',
                //   color: ['#fff']
                // }
              },
              itemStyle: {
                // 通常情况下：
                normal: {
                  color: ['#96BFFF']
                },
                areaStyle: {},
                // 鼠标悬停时：
                emphasis: {
                  shadowBlur: 10,
                  shadowOffsetX: 0,
                  shadowColor: 'rgba(0, 0, 0, 0.5)'
                }
              }
            } */
            ]
          }
          this.chartData.forEach(item => {
            option.dataset.source.push(item)
          })
          let myChart = echarts.init(document.getElementById('cityTime'))
          myChart.setOption(option)
        } else {
          this.$Message.error({
            content: '数据获取失败,\n' + ret.data.errmsg
          })
        }
      })
    }
  }
}
</script>

<style scoped>
  .header {
    height: 30px;
  }

  .icon {
    font-size: 28px;
    font-weight: 600;
    margin-right: 5px;
  }

  .title {
    font-size: 16px;
    font-weight: 600;
    line-height: 30px;
  }
</style>
